import React from 'react';
import { Modal, message } from 'antd';
import { formatMessage } from 'umi';
import { TipBox } from '../../../components';
import { auditTask } from '../../../services';
import styles from './index.less';

export const showAuditPassActionModal = (taskRecord, onOk) => {
    // console.log('showAuditPassActionModal -> taskRecord', taskRecord);
    const { id, taskOperateType } = taskRecord;
    Modal.confirm({
        title: '通过',
        content: <TipBox title="确定审核通过？" />,
        className: styles.confirmModal,
        okText: formatMessage({ id: 'btn.form.confirm' }),
        cancelText: formatMessage({ id: 'btn.form.cancel' }),
        onOk: () =>
            new Promise((resolve, reject) => {
                auditTask(id, taskOperateType, 1)
                    .then(res => {
                        const { code } = res;
                        if (code === 10000) {
                            if (onOk) onOk();
                            resolve();
                        } else {
                            message.error(res.msg);
                            reject();
                        }
                    })
                    .catch(() => {
                        reject();
                    });
            })
    });
};
